local skel = fk.CreateSkill{
  name = "sj8__zuiwo",
}

Fk:loadTranslationTable{
  ["sj8__zuiwo"] = "罪我",
  [":sj8__zuiwo"] = "若你最后一张失去的牌为【杀】，则你可以令一名其他角色弃置你一张手牌以视为使用【无懈可击】或【闪】。",

  ["#sj8__zuiwo"] = "罪我：你可以令一名其他角色弃置你一张手牌以视为使用【无懈可击】或【闪】",
  ["#sj8__zuiwo-ask"] = "罪我：令一名其他角色弃置你一张手牌以视为使用【%arg】",
  ["#sj8__zuiwo_dis"] = "罪我：弃置 %dest 一张手牌",
  ["@@sj8__zuiwo"] = "罪我",

  ["$sj8__zuiwo1"] = "",
  ["$sj8__zuiwo2"] = "",
}

skel:addEffect("viewas", {
  pattern = "jink,nullification",
  prompt = "#sj8__zuiwo",
  card_filter = Util.FalseFunc,
  interaction = function (self, player)
    local all_names = {"jink","nullification"}
    return UI.CardNameBox {
      choices = player:getViewAsCardNames(skel.name, all_names),
      all_choices = all_names,
    }
  end,
  view_as = function (self, player, cards)
    if Fk.all_card_types[self.interaction.data] == nil then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = skel.name
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    local to = room:askToChoosePlayers(player,{
      targets = room:getOtherPlayers(player),
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      prompt = "#sj8__zuiwo-ask:::"..Fk:translate(use.card.name),
      cancelable = false,
    })[1]
    local card = room:askToChooseCard(to,{
      target = player,
      flag = "h",
      skill_name = skel.name,
      prompt = "#sj8__zuiwo_dis::"..player.id,
    })
    room:throwCard(card,skel.name,player,to)
  end,
  enabled_at_play = function (self, player)
    return player:getMark("@@sj8__zuiwo") > 0 and not player:isKongcheng()
  end,
  enabled_at_response = function (self, player, response)
    return player:getMark("@@sj8__zuiwo") > 0 and not player:isKongcheng() and not response
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(skel.name,true,true) then
      local ids = {}
      for _, move in ipairs(data) do
        if move.from and move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if table.contains({Card.PlayerHand,Card.PlayerEquip},info.fromArea) then
              table.insertIfNeed(ids,info.cardId)
            end
          end
        end
      end
      if #ids > 0 then
        event:setCostData(self,{cards = ids})
        return true
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local cards = event:getCostData(self).cards
    player.room:setPlayerMark(player,"@@sj8__zuiwo",Fk:getCardById(cards[#cards]).trueName == "slash" and 1 or 0)
  end,
})


return skel
